// 浣跨敤鍘熺敓JavaScript鏂规硶浠ｆ浛mockjs
// import Mock from 'mockjs'
// const Random = Mock.Random

/**
 * 鐢熸垚闅忔満鏁存暟
 * @param min 鏈€灏忓€?
 * @param max 鏈€澶у€?
 */
function randomInteger(min: number, max: number): number {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
 * 鐢熸垚闅忔満娴偣鏁?
 * @param min 鏈€灏忓€?
 * @param max 鏈€澶у€?
 * @param decimals 灏忔暟浣嶆暟
 */
function randomFloat(min: number, max: number, decimals: number = 2): number {
  const value = Math.random() * (max - min) + min;
  return parseFloat(value.toFixed(decimals));
}

/**
 * 浠庢暟缁勪腑闅忔満閫夋嫨涓€椤?
 * @param arr 閫夐」鏁扮粍
 */
function randomPick<T>(arr: T[]): T {
  return arr[Math.floor(Math.random() * arr.length)];
}

/**
 * 鐢熸垚闅忔満ID
 */
function randomId(): string {
  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}

/**
 * 鐢熸垚闅忔満鏃ユ湡瀛楃涓?
 * @param format 鏃ユ湡鏍煎紡
 */
function randomDate(format: string = 'yyyy-MM-dd HH:mm:ss'): string {
  const now = new Date();
  const pastDate = new Date(now.getTime() - randomInteger(0, 30 * 24 * 60 * 60 * 1000));
  
  const year = pastDate.getFullYear();
  const month = String(pastDate.getMonth() + 1).padStart(2, '0');
  const day = String(pastDate.getDate()).padStart(2, '0');
  const hours = String(pastDate.getHours()).padStart(2, '0');
  const minutes = String(pastDate.getMinutes()).padStart(2, '0');
  const seconds = String(pastDate.getSeconds()).padStart(2, '0');
  
  return format
    .replace('yyyy', String(year))
    .replace('MM', month)
    .replace('dd', day)
    .replace('HH', hours)
    .replace('mm', minutes)
    .replace('ss', seconds);
}

/**
 * 鐢熸垚闅忔満涓枃鍚?
 */
function randomCName(): string {
  const firstNames = ['寮?, '鐜?, '鏉?, '璧?, '闄?, '鍒?, '鏉?, '榛?, '鍛?, '鍚?, '閮?, '瀛?, '椹?, '鏈?, '鑳?, '鏋?, '閮?, '浣?, '楂?, '缃?];
  const lastNames = ['鑺?, '濞?, '鏁?, '闈?, '绉€鑻?, '涓?, '寮?, '纾?, '娲?, '鍕?, '鑹?, '鏉?, '娑?, '鏄?, '瓒?, '闇?, '骞?, '鍒?, '妗傝嫳', '浣?];
  
  return randomPick(firstNames) + randomPick(lastNames);
}

/**
 * 鐢熸垚闅忔満瀛楃涓?
 * @param length 瀛楃涓查暱搴?
 * @param type 瀛楃涓茬被鍨?
 */
function randomString(type: 'lower' | 'upper' | 'number' | 'all' = 'all', length: number): string {
  let chars = '';
  
  if (type === 'lower' || type === 'all') chars += 'abcdefghijklmnopqrstuvwxyz';
  if (type === 'upper' || type === 'all') chars += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  if (type === 'number' || type === 'all') chars += '0123456789';
  
  let result = '';
  for (let i = 0; i < length; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  
  return result;
}

/**
 * 鐢熸垚闅忔満甯冨皵鍊?
 * @param probability true鐨勬鐜?
 */
function randomBoolean(probability: number = 0.5): boolean {
  return Math.random() < probability;
}

/**
 * 鐢熸垚闅忔満鍘跨骇鍦板潃
 */
function randomCounty(): string {
  const provinces = ['鍖椾含甯?, '涓婃捣甯?, '骞夸笢鐪?, '姹熻嫃鐪?, '娴欐睙鐪?, '鍥涘窛鐪?, '灞变笢鐪?, '婀栧寳鐪?, '娌冲崡鐪?, '杈藉畞鐪?];
  const cities = ['甯傝緰鍖?, '骞垮窞甯?, '娣卞湷甯?, '鍗椾含甯?, '鑻忓窞甯?, '鏉窞甯?, '瀹佹尝甯?, '鎴愰兘甯?, '姝︽眽甯?, '閮戝窞甯?, '瑗垮畨甯?];
  const counties = ['鏈濋槼鍖?, '娴锋穩鍖?, '绂忕敯鍖?, '鍗楀北鍖?, '濮戣嫃鍖?, '瑗挎箹鍖?, '姹熷寳鍖?, '闈掔緤鍖?, '姝︽槍鍖?, '閲戞按鍖?, '闆佸鍖?];
  
  return `${randomPick(provinces)}${randomPick(cities)}${randomPick(counties)}`;
}

/**
 * 鐢熸垚闅忔満涓枃鏍囬
 */
function randomTitle(min: number = 3, max: number = 7): string {
  const words = ['寮€鍙?, '璁捐', '鐮旂┒', '娴嬭瘯', '閮ㄧ讲', '杩愯惀', '璁″垝', '瀛︿範', '椤圭洰', '绯荤粺', '缃戠粶', '鏁版嵁', '绋嬪簭', '鍔熻兘', '鍒嗘瀽', '鎶ュ憡', '鏂规', '瀹炴柦', '璇勪及', '绠＄悊'];
  const length = randomInteger(min, max);
  let title = '';
  
  for (let i = 0; i < length; i++) {
    title += randomPick(words);
  }
  
  return title;
}

/**
 * 鐢熸垚绠＄悊鍛樹华琛ㄧ洏妯℃嫙鏁版嵁
 */
export function mockDashboardData() {
  const totalOrders = randomInteger(1000, 5000);
  const totalUsers = randomInteger(500, 2000);
  const totalProducts = randomInteger(200, 1000);
  const totalRevenue = randomFloat(10000, 100000);

  // 鐢熸垚鏈€杩戣鍗曟暟鎹?
  const recentOrders = [];
  for (let i = 0; i < 10; i++) {
    recentOrders.push({
      id: randomId(),
      orderNo: randomString('upper', 8),
      customer: randomCName(),
      amount: randomFloat(50, 500),
      status: randomPick(['寰呬粯娆?, '寰呭彂璐?, '宸插彂璐?, '宸插畬鎴?, '宸插彇娑?]),
      createTime: randomDate()
    });
  }

  // 鐢熸垚鏈€杩戠敤鎴锋暟鎹?
  const recentUsers = [];
  for (let i = 0; i < 10; i++) {
    recentUsers.push({
      id: randomId(),
      username: randomCName(),
      avatar: `https://randomuser.me/api/portraits/men/${randomInteger(1, 99)}.jpg`,
      createTime: randomDate(),
      status: randomBoolean() ? '姝ｅ父' : '绂佺敤'
    });
  }

  // 鐢熸垚閿€鍞暟鎹?
  const salesData = [];
  for (let i = 0; i < 7; i++) {
    const date = new Date();
    date.setDate(date.getDate() - i);
    salesData.push({
      date: formatDate(date),
      sales: randomFloat(1000, 10000)
    });
  }

  // 鐢熸垚鍒嗙被鏁版嵁
  const categoryData = [
    { name: '姹夊牎', value: randomInteger(100, 500) },
    { name: '鎶惃', value: randomInteger(100, 500) },
    { name: '楗枡', value: randomInteger(100, 500) },
    { name: '鐢滅偣', value: randomInteger(100, 500) },
    { name: '娌欐媺', value: randomInteger(100, 500) }
  ];

  return {
    totalOrders,
    totalUsers,
    totalProducts,
    totalRevenue,
    recentOrders,
    recentUsers,
    salesData,
    categoryData
  };
}

/**
 * 鐢熸垚鎺у埗鍙版瑙堟暟鎹?
 * @returns 鍖呭惈8涓叧閿寚鏍囩殑瀵硅薄
 */
export function generateDashboardOverviewData() {
  return {
    // 璁㈠崟鐩稿叧
    todayOrders: randomInteger(10, 200),
    
    // 鐢ㄦ埛鐩稿叧
    totalDistributors: randomInteger(50, 500),
    totalAgents: randomInteger(100, 1000),
    
    // 浜у搧鐩稿叧
    totalProducts: randomInteger(200, 2000),
    
    // 璐㈠姟鐩稿叧锛圲SDT锛?
    todayPaymentAmount: randomFloat(1000, 50000),
    totalRevenue: randomFloat(100000, 10000000),
    pendingWithdrawAmount: randomFloat(5000, 100000),
    totalWithdrawAmount: randomFloat(50000, 5000000),
    
    // 鏃堕棿鎴筹紝鐢ㄤ簬鏍囪鏁版嵁鐢熸垚鏃堕棿
    timestamp: new Date().getTime(),
    
    // 鍚屾瘮鏁版嵁锛堝闀跨巼锛岀敤鐧惧垎姣旇〃绀猴級
    growth: {
      todayOrders: randomFloat(-30, 100),
      totalDistributors: randomFloat(-10, 50),
      totalAgents: randomFloat(-10, 80),
      totalProducts: randomFloat(-5, 30),
      todayPaymentAmount: randomFloat(-20, 150),
      totalRevenue: randomFloat(-15, 120),
      pendingWithdrawAmount: randomFloat(-40, 200),
      totalWithdrawAmount: randomFloat(-10, 100)
    }
  };
}

/**
 * 鐢熸垚鏈€杩戞椿鍔ㄦ暟鎹?
 * @param count 闇€瑕佺敓鎴愮殑娲诲姩鏁伴噺
 * @returns 娲诲姩鏁版嵁鏁扮粍
 */
export function generateRecentActivitiesData(count = 10) {
  const activities = [];
  const activityTypes = [
    '鐢ㄦ埛娉ㄥ唽', '璁㈠崟鍒涘缓', '璁㈠崟鏀粯', '璁㈠崟鍙戣揣', '璁㈠崟瀹屾垚', 
    '鎻愭鐢宠', '鎻愭瀹℃牳', '鎻愭瀹屾垚', '浜у搧涓婃灦', '浜у搧涓嬫灦',
    '浠ｇ悊瀹℃牳', '缁忛攢鍟嗗鏍?, '绯荤粺鍏憡', '浣ｉ噾缁撶畻'
  ];
  
  for (let i = 0; i < count; i++) {
    const type = randomPick(activityTypes);
    let activity = {
      id: randomId(),
      type,
      time: randomDate(),
      timestamp: new Date().getTime() - randomInteger(0, 7 * 24 * 60 * 60 * 1000), // 鏈€杩?澶╁唴鐨勯殢鏈烘椂闂存埑
      content: '',
      user: {
        id: randomId(),
        name: randomCName(),
        role: randomPick(['绠＄悊鍛?, '缁忛攢鍟?, '浠ｇ悊', '鏅€氱敤鎴?]),
        avatar: `https://randomuser.me/api/portraits/${randomBoolean() ? 'men' : 'women'}/${randomInteger(1, 99)}.jpg`
      },
      status: '',
      needsAction: randomBoolean(0.3) // 30%姒傜巼闇€瑕佹搷浣?
    };
    
    // 鏍规嵁涓嶅悓娲诲姩绫诲瀷璁剧疆涓嶅悓鍐呭
    switch (type) {
      case '鐢ㄦ埛娉ㄥ唽':
        activity.content = `鏂扮敤鎴?${activity.user.name} 娉ㄥ唽鎴愬姛`;
        activity.status = '鎴愬姛';
        break;
      case '璁㈠崟鍒涘缓':
        const orderNo = randomString('upper', 8);
        activity.content = `鐢ㄦ埛 ${activity.user.name} 鍒涘缓浜嗚鍗?${orderNo}`;
        activity.status = '寰呮敮浠?;
        break;
      case '璁㈠崟鏀粯':
        const payOrderNo = randomString('upper', 8);
        const amount = randomFloat(50, 500);
        activity.content = `璁㈠崟 ${payOrderNo} 宸叉敮浠?${amount} USDT`;
        activity.status = '宸叉敮浠?;
        break;
      case '璁㈠崟鍙戣揣':
        const shipOrderNo = randomString('upper', 8);
        activity.content = `璁㈠崟 ${shipOrderNo} 宸插彂璐;
        activity.status = '宸插彂璐?;
        break;
      case '璁㈠崟瀹屾垚':
        const completeOrderNo = randomString('upper', 8);
        activity.content = `璁㈠崟 ${completeOrderNo} 宸插畬鎴恅;
        activity.status = '宸插畬鎴?;
        break;
      case '鎻愭鐢宠':
        const withdrawAmount = randomFloat(100, 10000);
        activity.content = `${activity.user.name} 鐢宠鎻愭 ${withdrawAmount} USDT`;
        activity.status = '寰呭鏍?;
        break;
      case '鎻愭瀹℃牳':
        const reviewAmount = randomFloat(100, 10000);
        activity.content = `鎻愭鐢宠 ${randomId()} 宸插鏍革紝閲戦 ${reviewAmount} USDT`;
        activity.status = randomBoolean() ? '宸查€氳繃' : '宸叉嫆缁?;
        break;
      case '鎻愭瀹屾垚':
        const completeAmount = randomFloat(100, 10000);
        activity.content = `鎻愭 ${randomId()} 宸插畬鎴愶紝閲戦 ${completeAmount} USDT`;
        activity.status = '宸插畬鎴?;
        break;
      case '浜у搧涓婃灦':
        const foods = ['姹夊牎', '鎶惃', '娌欐媺', '鐗涙帓', '鎰忛潰', '铔嬬硶', '濂惰尪'];
        const productName = randomTitle(2, 3) + randomPick(foods);
        activity.content = `浜у搧 ${productName} 宸蹭笂鏋禶;
        activity.status = '宸蹭笂鏋?;
        break;
      case '浜у搧涓嬫灦':
        const downFoods = ['姹夊牎', '鎶惃', '娌欐媺', '鐗涙帓', '鎰忛潰', '铔嬬硶', '濂惰尪'];
        const downProductName = randomTitle(2, 3) + randomPick(downFoods);
        activity.content = `浜у搧 ${downProductName} 宸蹭笅鏋禶;
        activity.status = '宸蹭笅鏋?;
        break;
      case '浠ｇ悊瀹℃牳':
        activity.content = `浠ｇ悊鐢宠 ${activity.user.name} 闇€瑕佸鏍竊;
        activity.status = '寰呭鏍?;
        break;
      case '缁忛攢鍟嗗鏍?:
        activity.content = `缁忛攢鍟嗙敵璇?${activity.user.name} 闇€瑕佸鏍竊;
        activity.status = '寰呭鏍?;
        break;
      case '绯荤粺鍏憡':
        activity.content = `鍙戝竷浜嗘柊鍏憡: ${randomTitle(5, 10)}`;
        activity.status = '宸插彂甯?;
        break;
      case '浣ｉ噾缁撶畻':
        const commissionAmount = randomFloat(50, 5000);
        activity.content = `瀹屾垚浣ｉ噾缁撶畻 ${commissionAmount} USDT`;
        activity.status = '宸茬绠?;
        break;
    }
    
    activities.push(activity);
  }
  
  // 鎸夋椂闂存埑鎺掑簭锛屾渶鏂扮殑鍦ㄥ墠
  activities.sort((a, b) => b.timestamp - a.timestamp);
  
  return activities;
}

/**
 * 鐢熸垚鍟嗘埛妯℃嫙鏁版嵁
 * @param count 鏁伴噺
 */
export function mockMerchants(count = 20) {
  const merchants = [];
  const categories = ['姹夊牎', '鎶惃', '楗枡', '鐢滅偣', '娌欐媺'];
  const merchantTypes = ['椁愬巺', '椋熷簻', '灏忓悆', '鐑х儰', '鐏攨'];
  
  for (let i = 0; i < count; i++) {
    merchants.push({
      id: randomId(),
      name: randomTitle(2, 4) + randomPick(merchantTypes),
      logo: `https://via.placeholder.com/80x80.png?text=${randomString('upper', 2)}`,
      address: randomCounty(),
      contact: randomCName(),
      phone: randomString('number', 11),
      email: `${randomString('lower', 8)}@example.com`,
      status: randomPick(['姝ｅ父', '寰呭鏍?, '宸茬鐢?]),
      createTime: randomDate('yyyy-MM-dd'),
      categoryName: randomPick(categories),
      rating: randomFloat(1, 5, 1),
      monthlySales: randomInteger(100, 5000)
    });
  }
  return merchants;
}

/**
 * 鐢熸垚鍟嗗搧妯℃嫙鏁版嵁
 * @param count 鏁伴噺
 */
export function mockProducts(count = 20) {
  const products = [];
  const categories = ['姹夊牎', '鎶惃', '楗枡', '鐢滅偣', '娌欐媺'];
  const foods = ['姹夊牎', '鎶惃', '娌欐媺', '鐗涙帓', '鎰忛潰', '铔嬬硶', '濂惰尪'];
  const merchantTypes = ['椁愬巺', '椋熷簻', '灏忓悆'];
  
  for (let i = 0; i < count; i++) {
    const name = randomTitle(2, 3) + randomPick(foods);
    products.push({
      id: randomId(),
      name,
      image: `https://via.placeholder.com/120x120.png?text=${name.substring(0, 2)}`,
      price: randomFloat(10, 200),
      originalPrice: randomFloat(10, 200),
      description: `杩欐槸涓€娆剧編鍛崇殑${name}锛屽彛鎰熸瀬浣筹紝娣卞彈椤惧鍠滅埍銆俙,
      merchantName: randomTitle(2, 3) + randomPick(merchantTypes),
      merchantId: randomId(),
      categoryName: randomPick(categories),
      status: randomPick(['涓婃灦', '涓嬫灦']),
      createTime: randomDate('yyyy-MM-dd'),
      sales: randomInteger(0, 1000),
      stock: randomInteger(0, 500)
    });
  }
  return products;
}

/**
 * 鐢熸垚璁㈠崟妯℃嫙鏁版嵁
 * @param count 鏁伴噺
 */
export function mockOrders(count = 20) {
  const orders = [];
  const foods = ['姹夊牎', '鎶惃', '娌欐媺', '鐗涙帓', '鎰忛潰', '铔嬬硶', '濂惰尪', '鍜栧暋', '涓夋槑娌?, '鐐搁浮', '钖潯', '鍐版穱娣?];
  const merchantTypes = ['椁愬巺', '椋熷簻', '灏忓悆', '鐑х儰', '鐏攨', '鍜栧暋鍘?, '鐢滃搧搴?, '濂惰尪搴?];
  const paymentMethods = ['寰俊鏀粯', '鏀粯瀹?, 'PayPal', '閾惰仈', 'USDT'];
  const orderStatuses = ['寰呬粯娆?, '寰呭彂璐?, '宸插彂璐?, '宸插畬鎴?, '宸插彇娑?];
  
  // 涓轰簡鐢熸垚鏇寸湡瀹炵殑璁㈠崟ID
  const orderIdPrefix = ['CO', 'KF', 'FD', 'OR'];
  
  // 鑾峰彇褰撳墠鏃ユ湡
  const now = new Date();
  
  for (let i = 0; i < count; i++) {
    // 鐢熸垚闅忔満鐨勪笅鍗曟棩鏈燂紙杩囧幓1-30澶╁唴锛?
    const orderDate = new Date(now);
    orderDate.setDate(orderDate.getDate() - randomInteger(1, 30));
    
    // 鏍煎紡鍖栦负"yyyy-MM-dd HH:mm:ss"鏍煎紡
    const orderTimeStr = randomDate('yyyy-MM-dd HH:mm:ss');
    
    // 闅忔満閫夋嫨涓€涓鍗曠姸鎬?
    const orderStatus = randomPick(orderStatuses);
    
    // 鏍规嵁璁㈠崟鐘舵佺'瀹氭敮浠樼姸鎬?
    let paymentStatus;
    if (orderStatus === '寰呬粯娆?) {
      paymentStatus = '寰呮敮浠?;
    } else if (orderStatus === '宸插彇娑?) {
      paymentStatus = randomBoolean(0.3) ? '宸查€€娆? : '寰呴€€娆?;
    } else {
      paymentStatus = '宸叉敮浠?;
    }
    
    // 鐢熸垚鏀粯鏃堕棿锛堝鏋滃凡鏀粯锛?
    const payTime = paymentStatus === '宸叉敮浠? ? 
      new Date(orderDate.getTime() + randomInteger(5, 60) * 60000) : null; // 5-60鍒嗛挓鍚?
    
    // 鐢熸垚1-5涓鍗曢"
    const items = [];
    const itemCount = randomInteger(1, 5);
    for (let j = 0; j < itemCount; j++) {
      const productName = randomTitle(2, 3) + randomPick(foods);
      const price = randomFloat(10, 100);
      const quantity = randomInteger(1, 5);
      
      items.push({
        id: randomId(),
        productName,
        productId: randomId(),
        price,
        quantity,
        subtotal: price * quantity
      });
    }

    // 璁＄畻鎬讳环
    const itemsTotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0).toFixed(2);
    const freightAmount = randomFloat(0, 20);
    const discountAmount = randomBoolean(0.3) ? randomFloat(5, 30) : 0;
    const totalAmount = parseFloat((itemsTotal + freightAmount - discountAmount).toFixed(2));

    // 鐢熸垚鏀惰揣浜轰俊鎭?
    const customerName = randomCName();
    const phone = randomString('number', 11);
    
    // 鐢熸垚璁㈠崟鍙?
    const orderNo = `${randomPick(orderIdPrefix)}${orderDate.getFullYear().toString().substring(2)}${(orderDate.getMonth() + 1).toString().padStart(2, '0')}${randomString('upper', 4)}${randomString('number', 6)}`;
    
    // 鐢熸垚鍟嗘埛淇℃伅
    const merchantName = randomTitle(2, 3) + randomPick(merchantTypes);
    
    orders.push({
      id: randomId(),
      orderNo,
      orderTime: orderTimeStr,
      customerName,
      customerPhone: phone,
      customerId: randomId(),
      merchantName,
      merchantId: randomId(),
      status: orderStatus,
      paymentStatus,
      paymentMethod: randomPick(paymentMethods),
      payTime: payTime ? randomDate('yyyy-MM-dd HH:mm:ss') : null,
      address: randomCounty() + randomString('number', 3) + '鍙?,
      items,
      itemsCount: items.length,
      itemsTotal: parseFloat(itemsTotal.toFixed(2)),
      freightAmount,
      discountAmount,
      totalAmount,
      remark: randomBoolean(0.3) ? `璇?{randomPick(['灏藉揩鍙戣揣', '閫侀涓婇棬', '纭鍦板潃', '涓嶈杈?, '澶氬姞鐐规枡', '鍖呰灏忓績'])}` : ''
    });
  }
  
  // 鎸変笅鍗曟椂闂撮檷搴忔帓搴忥紙鏈€鏂扮殑鍦ㄥ墠闈
  orders.sort((a, b) => new Date(b.orderTime).getTime() - new Date(a.orderTime).getTime());
  
  return orders;
}

/**
 * 灏嗕腑鏂囪浆鎹繃鎷奸煶锛堢畝鍖栫増锛?
 * 鐢ㄤ簬鏍规嵁涓鍗曟棩鏈熸棩鏈?
 */
function toPinyin(chinese: string): string {
  // 绠鍖栫殑鎷奸煶鏄犲皠琛紝浠呭寘鍚竴浜涘父瑙佹眽瀛?
  const pinyinMap = {
    '鏉?: 'li', '鐜?: 'wang', '寮?: 'zhang', '鍒?: 'liu', '闄?: 'chen',
    '鏉?: 'yang', '璧?: 'zhao', '榛?: 'huang', '鍛?: 'zhou', '鍚?: 'wu',
    '寰?: 'xu', '瀛?: 'sun', '鑳?: 'hu', '鏈?: 'zhu', '楂?: 'gao',
    '鏋?: 'lin', '浣?: 'he', '閮?: 'guo', '椹?: 'ma', '缃?: 'luo',
    '姊?: 'liang', '瀹?: 'song', '閮?: 'zheng', '璋?: 'xie', '闊?: 'han',
    '鍞?: 'tang', '鍐?: 'feng', '浜?: 'yu', '钁?: 'dong', '钀?: 'xiao',
    '绋?: 'cheng', '鏇?: 'cao', '琚?: 'yuan', '閭?: 'deng', '璁?: 'xu',
    '鍌?: 'fu', '娌?: 'shen', '鏇?: 'zeng', '褰?: 'peng', '鍚?: 'lv',
    '鑻?: 'su', '鍗?: 'lu', '钂?: 'jiang', '钄?: 'cai', '璐?: 'jia',
    '涓?: 'ding', '榄?: 'wei', '钖?: 'xue', '鍙?: 'ye', '闃?: 'yan',
    '浣?: 'yu', '娼?: 'pan', '鏉?: 'du', '鎴?: 'dai', '澶?: 'xia',
    '閽?: 'zhong', '姹?: 'wang', '鐢?: 'tian', '浠?: 'ren', '濮?: 'jiang',
    '鑼?: 'fan', '鏂?: 'fang', '鐭?: 'shi', '濮?: 'yao', '璋?: 'tan',
    '鐩?: 'sheng', '閭?: 'zou', '鐔?: 'xiong', '閲?: 'jin', '闄?: 'lu',
    '閮?: 'hao', '瀛?: 'kong', '鐧?: 'bai', '宕?: 'cui', '搴?: 'kang',
    '姣?: 'mao', '閭?: 'qiu', '绉?: 'qin', '姹?: 'jiang', '鍙?: 'shi',
    '椤?: 'gu', '渚?: 'hou', '閭?: 'shao', '瀛?: 'meng', '榫?: 'long',
    '涓?: 'wan', '娈?: 'duan', '闆?: 'lei', '閽?: 'qian', '姹?: 'tang',
    '灏?: 'yin', '榛?: 'li', '鏄?: 'yi', '甯?: 'chang', '姝?: 'wu',
    '涔?: 'qiao', '璐?: 'he', '璧?: 'lai', '榫?: 'gong', '鏂?: 'wen',
    '鏄?: 'ming', '鍗?: 'hua', '澶?: 'tian', '浼?: 'wei', '寤?: 'jian',
    '鍥?: 'guo', '骞?: 'ping', '蹇?: 'zhi', '寮?: 'qiang', '涓?: 'dong',
    '娴?: 'hai', '灏?: 'xiao', '鍐?: 'jun', '姘?: 'min', '灞?: 'shan',
    '姘?: 'shui', '姘?: 'yong', '涓?: 'shi', '娲?: 'yang', '瀛?: 'zi'
  };

  let pinyin = '';
  for (let i = 0; i < chinese.length; i++) {
    const char = chinese.charAt(i);
    pinyin += pinyinMap[char] || char;
  }
  return pinyin.toLowerCase();
}

/**
 * 鐢熸垚妯℃嫙鐢ㄦ埛鏁版嵁
 * @param count 鐢熸垚鐨勭敤鎴锋暟閲?
 * @param type 鐢ㄦ埛绫诲瀷锛屽彲閫夐」锛?鍖哄煙浠ｇ悊'銆?鍒嗛攢鍟?銆?鏅鍦板潃锛屼笉鎸囧畾鍒欑敓鎴愭墍鏈夌被鍨?
 * @returns 鐢ㄦ埛鏁版嵁鏁扮粍
 */
export function generateUsersData(count: number = 50, type?: string): any[] {
  const users = [];
  const userTypes = ['鍖哄煙浠ｇ悊', '鍒嗛攢鍟?, '鏅鍦板潃'];
  const statuses = ['娲昏穬', '宸茬鐢?];
  
  // 楠岃瘉绫诲瀷鍙傛暟
  if (type && !userTypes.includes(type)) {
    console.warn(`鏃犳晥鐨勭敤鎴风被鍨? ${type}锛屽皢鐢熸垚鎵€鏈夌被鍨嬬殑鐢ㄦ埛鏁版嵁`);
    type = undefined;
  }
  
  // 鐢ㄤ簬鐢熸垚鐢ㄦ埛鍚嶇殑濮撴皬鍜屽悕瀛楅儴鍒?
  const surnames = ['鏉?, '鐜?, '寮?, '鍒?, '闄?, '鏉?, '璧?, '榛?, '鍛?, '鍚?, '寰?, '瀛?, '椹?, '鏈?, '鑳?, '鏋?, '楂?, '浣?, '閮?, '缃?];
  const names = ['鏄?, '鍗?, '浼?, '寮?, '鍐?, '鏉?, '濞?, '鑹?, '娑?, '瓒?, '鍕?, '闈?, '鏁?, '纾?, '鍒?, '鑺?, '涓?, '绉€', '濞?, '鑻?];
  
  // 閭鍩熷悕
  const emailDomains = ['qq.com', '163.com', 'gmail.com', 'outlook.com', 'hotmail.com', 'sina.com', 'sohu.com', '126.com', 'foxmail.com', 'yahoo.com'];
  
  // 鐢ㄦ埛澶村儚鐨勯殢鏈哄浘鐗?
  const avatarBase = 'https://randomuser.me/api/portraits/';
  
  for (let i = 0; i < count; i++) {
    // 鐢熸垚鐢ㄦ埛鍩烘湰淇℃伅
    const surname = surnames[Math.floor(Math.random() * surnames.length)];
    const name = names[Math.floor(Math.random() * names.length)];
    const username = surname + name + (Math.random() > 0.7 ? Math.floor(Math.random() * 100) : '');
    
    // 濡傛灉鎸囧畾浜嗙被鍨嬶紝鍒欎娇鐢ㄨ绫诲瀷锛屽惁鍒欓殢鏈洪€夋嫨涓€涓鍨?
    const userType = type || userTypes[Math.floor(Math.random() * userTypes.length)];
    
    // 鐢熸垚閭鍩鐨勭敤鎴峰悕浣滀负閭鍩鐢ㄦ埛鍚嶉儴鍒?
    const emailUsername = toPinyin(username);
    const domain = emailDomains[Math.floor(Math.random() * emailDomains.length)];
    const email = `${emailUsername}${Math.random() > 0.5 ? Math.floor(Math.random() * 1000) : ''}@${domain}`;
    
    // 闅忔満鐢熸垚鎵嬫満鍙?
    const phone = '1' + (Math.floor(Math.random() * 5) + 3) + Array.from({length: 9}, () => Math.floor(Math.random() * 10)).join('');
    
    // 澶村儚
    const gender = Math.random() > 0.5 ? 'men' : 'women';
    const avatarIndex = Math.floor(Math.random() * 70);
    const avatar = `${avatarBase}${gender}/${avatarIndex}.jpg`;
    
    // 娉ㄥ唽鏃堕棿锛堣繃鍘?骞村唴锛?
    const now = new Date();
    const threeYearsAgo = new Date(now);
    threeYearsAgo.setFullYear(now.getFullYear() - 3);
    const registerTime = new Date(threeYearsAgo.getTime() + Math.random() * (now.getTime() - threeYearsAgo.getTime()));
    const registerTimeStr = registerTime.toISOString().split('T')[0];
    
    // 鐢ㄦ埛鐘舵侊紙澶ч儴鍒嗙敤鎴锋槸娲昏穬鐨勶級
    const status = Math.random() > 0.15 ? statuses[0] : statuses[1];
    
    // 涓婃鐧诲綍鏃堕棿锛堝鏋滄槸娲昏穬鐢ㄦ埛锛屽垯涓烘渶杩戜竴涓鍨?
    let lastLoginTime = null;
    if (status === '娲昏穬') {
      const oneMonthAgo = new Date(now);
      oneMonthAgo.setMonth(now.getMonth() - 1);
      const lastLogin = new Date(oneMonthAgo.getTime() + Math.random() * (now.getTime() - oneMonthAgo.getTime()));
      lastLoginTime = lastLogin.toISOString().split('T')[0] + ' ' + 
                     String(lastLogin.getHours()).padStart(2, '0') + ':' +
                     String(lastLogin.getMinutes()).padStart(2, '0');
    } else if (Math.random() > 0.3) { // 閮ㄥ垎宸茬鐢ㄧ敤鎴锋湁鐧诲綍璁板綍
      const sixMonthsAgo = new Date(now);
      sixMonthsAgo.setMonth(now.getMonth() - 6);
      const threeMonthsAgo = new Date(now);
      threeMonthsAgo.setMonth(now.getMonth() - 3);
      const lastLogin = new Date(sixMonthsAgo.getTime() + Math.random() * (threeMonthsAgo.getTime() - sixMonthsAgo.getTime()));
      lastLoginTime = lastLogin.toISOString().split('T')[0] + ' ' + 
                     String(lastLogin.getHours()).padStart(2, '0') + ':' +
                     String(lastLogin.getMinutes()).padStart(2, '0');
    }
    
    // 璁㈠崟鏁伴噺鍜屾秷璐规€婚
    let orderCount = 0;
    let totalSpend = 0;
    
    if (userType === '鏅鍦板潃') {
      // 鏅鍦板潃鐨勮鍦板潃 0-30锛屾秷璐规€婚 0-10000
      orderCount = Math.floor(Math.random() * 31);
      totalSpend = Math.floor(Math.random() * 10001);
    } else if (userType === '鍒嗛攢鍟?) {
      // 鍒嗛攢鍟嗙殑璁㈠崟鏁伴噺 5-50锛屾秷璐规€婚 1000-20000
      orderCount = Math.floor(Math.random() * 46) + 5;
      totalSpend = Math.floor(Math.random() * 19001) + 1000;
    } else if (userType === '鍖哄煙浠ｇ悊') {
      // 鍖哄煙浠ｇ悊鐨勮鍦板潃20-100锛屾秷璐规€婚 5000-50000
      orderCount = Math.floor(Math.random() * 81) + 20;
      totalSpend = Math.floor(Math.random() * 45001) + 5000;
    }
    
    // 濡傛灉鐢ㄦ埛琚鍨嬶紝鍑忓皯璁㈠崟鏁伴噺鍜屾秷璐归
    if (status === '宸茬鐢?) {
      orderCount = Math.floor(orderCount * 0.3);
      totalSpend = Math.floor(totalSpend * 0.3);
    }
    
    users.push({
      id: `user-${i + 1}`,
      username,
      userType,
      avatar,
      email,
      phone,
      registerTime: registerTimeStr,
      status,
      lastLoginTime,
      orderCount,
      totalSpend
    });
  }
  
  return users;
}

/**
 * 鐢熸垚鐢ㄦ埛璇︾粏淇℃伅鏁版嵁
 * @param userId 鐢ㄦ埛ID
 * @returns 鐢ㄦ埛璇︾粏淇℃伅瀵硅薄
 */
export function generateUserDetailData(userId: string): any {
  // 妯℃嫙鑾峰彇鐢ㄦ埛璇︽儏鏁版嵁
  // 鍦ㄧ湡瀹炵幆澧冧腑锛岃繖閲屼細璋冪敤API鑾峰彇鐢ㄦ埛璇︾粏淇℃伅
  const allUsers = generateUsersData(100);
  const user = allUsers.find(u => u.id === userId);
  
  if (!user) {
    return null;
  }
  
  // 鑾峰彇鐢ㄦ埛绫诲瀷
  const userType = user.userType || '鏅鍦板潃';
  
  // 鎵╁睍鐢ㄦ埛淇℃伅
  return generateExtendedUserData(user);
}

/**
 * 鐢熸垚鎵╁睍鐢ㄦ埛鏁版嵁
 * @param baseUser 鍩虹鐢ㄦ埛鏁版嵁
 * @returns 鎵╁睍鍚庣殑鐢ㄦ埛璇︾粏鏁版嵁
 */
function generateExtendedUserData(user: any): any {
  const now = new Date();
  
  // 榛樿鐨勮处鎴蜂俊鎭?
  const accountInfo = {
    accountStatus: user.status === '娲昏穬' ? '姝ｅ父' : '绂佺敤',
    registrationIP: `${Math.floor(Math.random() * 255)}.${Math.floor(Math.random() * 255)}.${Math.floor(Math.random() * 255)}.${Math.floor(Math.random() * 255)}`,
    emailVerified: Math.random() > 0.2,
    phoneVerified: Math.random() > 0.3,
    twoFactorEnabled: Math.random() > 0.7,
    passwordLastChanged: new Date(now.getTime() - Math.random() * 90 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
    lastFailedLogin: Math.random() > 0.8 ? new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0] : null,
    failedLoginAttempts: Math.random() > 0.8 ? Math.floor(Math.random() * 5) : 0,
  };

  // 鎵╁睍鐢ㄦ埛淇℃伅
  const extendedUser = {
    ...user,
    accountInfo,
  };
  
  // 涓哄垎閿鍟嗘垨鍖哄煙浠ｇ悊娣诲姞涓氱哗鏁版嵁
  if (user.userType === '鍒嗛攢鍟? || user.userType === '鍖哄煙浠ｇ悊') {
    extendedUser.performanceData = {
      totalCommission: Math.floor(Math.random() * 10000) + 5000,
      unpaidCommission: Math.floor(Math.random() * 3000) + 500,
      commissionRate: `${(Math.random() * 10 + 5).toFixed(1)}%`,
      totalReferrals: Math.floor(Math.random() * 100) + 10,
      activeReferrals: Math.floor(Math.random() * 50) + 5,
      lastCommissionDate: new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
      monthlySales: generateMonthlySalesData(6),
    };
    
    // 涓哄垎閿鍟嗕紭鍖栦剑閲戞暟鎹?
    if (user.userType === '鍒嗛攢鍟?) {
      // 澧炲姞鎬讳剑閲戦噾棰濓紝浣垮叾鏇村姞鏄捐憲
      extendedUser.performanceData.totalCommission = Math.floor(Math.random() * 50000) + 20000;
      // 璁剧疆鏈彁鐜颁剑閲戜负鎬讳剑閲戠殑涓瀹氭瘮渚?
      extendedUser.performanceData.unpaidCommission = Math.floor(extendedUser.performanceData.totalCommission * (Math.random() * 0.3 + 0.1));
    }
  }
  
  // 涓哄尯鍩熶唬鐞嗘坊鍔犵綉缁滄暟鎹?
  if (user.userType === '鍖哄煙浠ｇ悊') {
    const totalDistributors = Math.floor(Math.random() * 50) + 20;
    const activeDistributors = Math.floor(totalDistributors * (Math.random() * 0.5 + 0.4));
    
    extendedUser.networkData = {
      totalDistributors,
      activeDistributors,
      inactiveDistributors: totalDistributors - activeDistributors,
      pendingApprovals: Math.floor(Math.random() * 5),
      networkGrowthRate: `${(Math.random() * 20 - 5).toFixed(1)}%`,
      averageDistributorSales: Math.floor(Math.random() * 5000) + 2000,
      topDistributors: generateTopDistributors(Math.min(5, totalDistributors)),
    };
  }
  
  return extendedUser;
}

// 鐢熸垚鏈堝害閿鍞暟鎹?
function generateMonthlySalesData(months: number): Array<{ month: string; sales: number }> {
  const now = new Date();
  const currentYear = now.getFullYear();
  const currentMonth = now.getMonth();
  
  return Array.from({ length: months }).map((_, index) => {
    const monthIndex = (currentMonth - index + 12) % 12;
    const year = currentYear - Math.floor((index - currentMonth) / 12);
    const sales = Math.floor(Math.random() * 50000) + 10000;
    
    return {
      month: `${year}骞?{monthIndex + 1}鏈坄`,
      sales
    };
  }).reverse();
}

// 鐢熸垚椤剁骇鍒嗛攢鍟?
function generateTopDistributors(count: number): Array<any> {
  const now = new Date();
  const currentYear = now.getFullYear();
  
  return Array.from({ length: count }).map((_, index) => {
    const joinYear = currentYear - Math.floor(Math.random() * 3);
    const joinMonth = Math.floor(Math.random() * 12) + 1;
    const joinDay = Math.floor(Math.random() * 28) + 1;
    
    return {
      name: `鍒嗛攢鍟?{Math.floor(Math.random() * 1000)}`,
      joinDate: `${joinYear}-${joinMonth.toString().padStart(2, '0')}-${joinDay.toString().padStart(2, '0')}`,
      activeReferrals: Math.floor(Math.random() * 30) + 5,
      sales: Math.floor(Math.random() * 100000) + 50000
    };
  }).sort((a, b) => b.sales - a.sales);
}

// 杈呭姪鍑芥暟锛氱敓鎴愰殢鏈鸿繃鍘绘棩鏈?
function getRandomPastDate(minDaysAgo: number, maxDaysAgo: number): string {
  const today = new Date();
  const daysAgo = Math.floor(Math.random() * (maxDaysAgo - minDaysAgo + 1)) + minDaysAgo;
  const pastDate = new Date(today);
  pastDate.setDate(today.getDate() - daysAgo);
  return pastDate.toISOString().split('T')[0];
}

// 杈呭姪鍑芥暟锛氱敓鎴愰殢鏈哄嚭鐢熸棩鏈?
function getRandomBirthDate(): string {
  const year = Math.floor(Math.random() * 40) + 1960;
  const month = Math.floor(Math.random() * 12) + 1;
  const day = Math.floor(Math.random() * 28) + 1;
  return `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
}

// 杈呭姪鍑芥暟锛氱敓鎴愬叏鍚?
function generateFullName(username: string): string {
  const surnames = ['鏉?, '鐜?, '寮?, '鍒?, '闄?, '鏉?, '璧?, '榛?, '鍛?, '鍚?, '寰?, '瀛?, '鏈?, '椹?, '鑳?, '閮?, '鏋?, '浣?];
  
  // 濡傛灉鐢ㄦ埛鍚嶅凡缁忔槸涓鍗曟枃鍚嶏紝鐩存帴杩斿洖
  if (/^[\u4e00-\u9fa5]{2,4}$/.test(username)) {
    return username;
  }
  
  const surname = surnames[Math.floor(Math.random() * surnames.length)];
  const givenName = ['鏄?, '鑺?, '鍐?, '鍗?, '寮?, '浼?, '鏉?, '濞?, '鑹?, '鏁?, '闈?, '涓?, '娑?, '瓒?, '鍕?, '娲?, '鐕?, '鏅?, '纾?][Math.floor(Math.random() * 19)];
  
  return surname + givenName;
}

// 杈呭姪鍑芥暟锛氱敓鎴愪釜浜虹畝浠?
function generateBio(): string {
  const bios = [
    '鐑埍缇庨鍜屾帰绱㈡柊椁愬巺鐨勭編椋熺埍濂借€?,
    '涓撴敞浜庡仴搴烽ギ椋熷拰鏈夋満椋熷搧鐨勫€″鑰?,
    '缁忛獙涓板瘜鐨勭編椋熷崥涓伙紝鍠滄鍒嗕韩缇庨浣撻獙',
    '缇庨涓庡仴搴风敓娲绘柟寮忕殑骞宠杩芥眰鑰?,
    '鍠滄灏濊瘯鍚勫浗缇庨锛屽鍚勪浜氭床鑿滅郴灏や负鐑埍',
    '椁愰ギ琛屼笟浠庝笟鑰咃紝鑷村姏浜庢彁渚涗紭璐ㄩ楗熺埍楠?,
    '娉ㄩ噸椋熷搧鍝佽川鍜屾湇鍔＄殑蹇犲疄娑堣垂鑰?,
    '鍒涙柊椁愰ギ鐞嗗康鐨勬帹鍔ㄨ€咃紝鍏虫敞椋熷搧琛屼笟鍙戝睍',
    '缇庨鎽勫奖鐖卞ソ鑰咃紝鍠勪簬鍙戠幇椋熺墿鐨勭編鎰?,
    '缁忓父缁勭粐鏈嬪弸鑱氶鍚戝尯銆俙;
  ];
  
  return bios[Math.floor(Math.random() * bios.length)];
}

// 杈呭姪鍑芥暟锛氱敓鎴愰殢鏈轰綅缃?
function getRandomLocation(): string {
  const provinces = ['鍖椾含甯?, '涓婃捣甯?, '骞夸笢鐪?, '姹熻嫃鐪?, '娴欐睙鐪?, '鍥涘窛鐪?, '婀栧寳鐪?, '婀栧崡鐪?, '娌冲崡鐪?, '娌冲寳鐪?];
  const cities = {
    '鍖椾含甯?: ['鏈濋槼鍖?, '娴锋穩鍖?, '涓滃煄鍖?, '瑗垮煄鍖?, '涓板彴鍖?],
    '涓婃捣甯?: ['娴︿笢鏂板尯', '榛勬郸鍖?, '寰愭眹鍖?, '闈欏畨鍖?, '闀垮畞鍖?],
    '骞夸笢鐪?: ['骞垮窞甯?, '娣卞湷甯?, '涓滆帪甯?, '浣涘北甯?, '鐝犳捣甯?],
    '姹熻嫃鐪?: ['鍗椾含甯?, '鑻忓窞甯?, '鏃犻敗甯?, '甯稿窞甯?, '鎵窞甯?],
    '娴欐睙鐪?: ['鏉鍦板潃甯?, '瀹佹尝甯?, '娓╁窞甯?, '缁嶅叴甯?, '鍢夊叴甯?],
    '鍥涘窛鐪?: ['鎴愰兘甯?, '缁甸槼甯?, '寰烽槼甯?, '涔愬北甯?, '鍗楀厖甯?],
    '婀栧寳鐪?: ['姝︽眽甯?, '瀹滄槍甯?, '瑗勯槼甯?, '鑽嗗窞甯?, '榛勭煶甯?],
    '婀栧崡鐪?: ['闀挎矙甯?, '鏍床甯?, '婀樻江甯?, '琛￠槼甯?, '宀抽槼甯?],
    '娌冲崡鐪?: ['閮戝窞甯?, '娲涢槼甯?, '寮灏佸競', '瀹夐槼甯?, '鍗楅槼甯?],
    '娌冲寳鐪?: ['鐭冲搴勫競', '鍞愬北甯?, '淇濆畾甯?, '閭兏甯?, '绉︾殗宀涘競']
  };
  
  const province = provinces[Math.floor(Math.random() * provinces.length)];
  const cityList = cities[province as keyof typeof cities] || cities['鍖椾含甯?];
  const city = cityList[Math.floor(Math.random() * cityList.length)];
  
  return `${province} ${city}`;
}

// 杈呭姪鍑芥暟锛氱敓鎴愬晢涓氬悕绉?
function generateBusinessName(username: string): string {
  const prefixes = ['浼樺搧', '榧庣洓', '鎭掍俊', '閲戞辰', '鐩涗笘', '瀹忚揪', '鍏寸洓', '鐟炰赴', '璇氫俊', '鍗庡叴'];
  const suffixes = ['璐告槗鏈夐檺鍏徃', '鍟嗚锤涓績', '椋熷搧鏈夐檺鍏徃', '鍟嗕笟杩為攣', '閰嶉€佹湇鍔′腑蹇?, '椁愰ギ闆嗗洟', '椋熷搧閰嶉€?, '椁愰ギ绠＄悊'];
  
  const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
  const suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
  
  // 浠庣敤鎴峰悕鐢熸垚鍟嗕笟鍚嶇О鐨勪竴閮ㄥ垎
  let nameSegment = '';
  if (/^[\u4e00-\u9fa5]{2,4}$/.test(username)) {
    // 濡傛灉鏄腑鏂囧悕锛屽彇绗竴涓瓧
    nameSegment = username.slice(0, 1);
  } else {
    // 鍚﹀垯鐢熸垚涓鍨殢鏈轰腑鏂囧瓧
    nameSegment = ['婧?, '閼?, '鐩?, '椤?, '浣?, '绂?, '鏄?, '娉?][Math.floor(Math.random() * 8)];
  }
  
  return `${prefix}${nameSegment}${suffix}`;
}

// 杈呭姪鍑芥暟锛氱敓鎴愯惀涓氭墽鐓у彿
function generateBusinessLicense(): string {
  // 缁熶竴绀句細淇敤浠ｇ爜鏍煎紡
  let license = '';
  const chars = '0123456789ABCDEFGHJKLMNPQRTUWXY';
  
  for (let i = 0; i < 18; i++) {
    license += chars[Math.floor(Math.random() * chars.length)];
  }
  
  return license;
}

// 杈呭姪鍑芥暟锛氱敓鎴愮◣鍙?
function generateTaxId(): string {
  let taxId = '';
  
  for (let i = 0; i < 15; i++) {
    taxId += Math.floor(Math.random() * 10).toString();
  }
  
  return taxId;
}

// 杈呭姪鍑芥暟锛氱敓鎴愬晢涓氬湴鍧€
function getRandomBusinessAddress(): string {
  const provinces = ['鍖椾含甯?, '涓婃捣甯?, '骞夸笢鐪?, '姹熻嫃鐪?, '娴欐睙鐪?];
  const cities = {
    '鍖椾含甯?: ['鏈濋槼鍖?, '娴锋穩鍖?, '涓板彴鍖?],
    '涓婃捣甯?: ['娴︿笢鏂板尯', '榛勬郸鍖?, '寰愭眹鍖?],
    '骞夸笢鐪?: ['骞垮窞甯?, '娣卞湷甯?, '涓滆帪甯?],
    '姹熻嫃鐪?: ['鍗椾含甯?, '鑻忓窞甯?, '鏃犻敗甯?],
    '娴欐睙鐪?: ['鏉鍦板潃甯?, '瀹佹尝甯?, '娓╁窞甯?]
  };
  const streets = ['涓鍗曟北璺?, '浜烘皯澶ч亾', '寤鸿璺?, '瑙ｆ斁璺?, '鍜屽钩璺?, '鍗椾含璺?, '涓滈璺?, '闀垮畨琛?, '澶╁簻澶ч亾', '閲戣瀺琛?];
  const buildings = ['鍥介檯澶у帵', '鍟嗗姟涓績', '浼佷笟骞垮満', '鍒涙柊鍥?, '绉戞妧澶у帵', '鍟嗕笟骞垮満', '璐㈠瘜涓績', '閲戣瀺涓績'];
  
  const province = provinces[Math.floor(Math.random() * provinces.length)];
  const cityList = cities[province as keyof typeof cities];
  const city = cityList[Math.floor(Math.random() * cityList.length)];
  const street = streets[Math.floor(Math.random() * streets.length)];
  const building = buildings[Math.floor(Math.random() * buildings.length)];
  const number = Math.floor(Math.random() * 100) + 1;
  const floor = Math.floor(Math.random() * 20) + 1;
  const room = Math.floor(Math.random() * 20) + 1;
  
  return `${province}${city}${street}${number}鍙?{building}${floor}妤?{room < 10 ? '0' + room : room}瀹;
}

// 杈呭姪鍑芥暟锛氱敓鎴愯亴浣?
function getRandomPosition(): string {
  const positions = ['鎬荤粡鐞?, '閿鍞€荤洃', '杩愯惀鎬荤洃', '甯傚満缁忕悊', '鍖哄煙璐熻矗浜?, '鍟嗗姟浠ｈ〃', '涓氬姟缁忕悊', '鍒涘浜?, '鍚堜紮浜?, '搴楅暱'];
  return positions[Math.floor(Math.random() * positions.length)];
}

// 杈呭姪鍑芥暟锛氱敓鎴愮綉绔?
function generateWebsite(username: string): string {
  const domains = ['.com', '.cn', '.net', '.com.cn', '.shop', '.food'];
  const prefixes = ['shop', 'food', 'eat', 'delicious', 'tasty', 'yummy', 'fresh'];
  
  let siteName = '';
  if (/^[\u4e00-\u9fa5]{2,4}$/.test(username)) {
    // 涓鍗曟枃鍚嶈浆鎷奸煶
    const pinyinChars = {
      '鏉?: 'li', '鐜?: 'wang', '寮?: 'zhang', '鍒?: 'liu', '闄?: 'chen', 
      '鏉?: 'yang', '璧?: 'zhao', '榛?: 'huang', '鍛?: 'zhou', '鍚?: 'wu'
    };
    const firstChar = username.charAt(0);
    siteName = pinyinChars[firstChar as keyof typeof pinyinChars] || prefixes[Math.floor(Math.random() * prefixes.length)];
  } else {
    // 鑻辨枃鍚嶇洿鎺ヤ娇鐢?
    siteName = username.toLowerCase().replace(/[^a-z0-9]/g, '');
  }
  
  if (!siteName || siteName.length < 3) {
    siteName = prefixes[Math.floor(Math.random() * prefixes.length)];
  }
  
  const randomNum = Math.floor(Math.random() * 1000);
  const domain = domains[Math.floor(Math.random() * domains.length)];
  
  return `www.${siteName}${randomNum}${domain}`;
}

// 杈呭姪鍑芥暟锛氱敓鎴愭湀搴﹂攢鍞暟鎹?
function generateMonthlySales(): Array<{ month: string; sales: number }> {
  const monthNames = ['1鏈?, '2鏈?, '3鏈?, '4鏈?, '5鏈?, '6鏈?, '7鏈?, '8鏈?, '9鏈?, '10鏈?, '11鏈?, '12鏈?];
  const currentMonth = new Date().getMonth();
  const monthlySales = [];
  
  // 鐢熸垚鏈杩涓鐨勯攢鍞暟鎹?
  for (let i = 5; i >= 0; i--) {
    const monthIndex = (currentMonth - i + 12) % 12;
    const year = new Date().getFullYear() - (currentMonth < i ? 1 : 0);
    
    monthlySales.push({
      month: `${year}骞?{monthNames[monthIndex]}`,
      sales: Math.floor(Math.random() * 40000) + 5000
    });
  }
  
  return monthlySales;
}

// 杈呭姪鍑芥暟锛氱敓鎴愮儹閿€浜у搧
function generateTopProducts(): Array<{ name: string; salesCount: number; price: number }> {
  const products = [
    '鎷涚墝鐐掗キ', '榛勭剸楦＄背楗?, '楹昏荆棣欓攨', '瀹繚楦′竵', '灏忕倰鑲?, '姘寸叜鑲夌墖',
    '楸奸鑲変笣', '鍥為攨鑲?, '閰歌彍楸?, '楹诲﹩璞嗚厫', '杈ｅ瓙楦?, '骞查攨鐗涜倝',
    '钂滆嫈鐐掕倝', '钂滆搲瑗垮叞鑺?, '绯栭唻鎺掗', '绾㈢儳鐙瓙澶?, '涓滃潯鑲樺瓙', '绾㈢儳楸?
  ];
  
  const topProducts = [];
  const usedProducts = new Set();
  
  // 鐢熸垚3-5涓儹閿€浜у搧
  const count = Math.floor(Math.random() * 3) + 3;
  
  for (let i = 0; i < count; i++) {
    let productName;
    
    // 纭繚浜у搧涓嶉噸澶?
    do {
      productName = products[Math.floor(Math.random() * products.length)];
    } while (usedProducts.has(productName));
    
    usedProducts.add(productName);
    
    topProducts.push({
      name: productName,
      salesCount: Math.floor(Math.random() * 500) + 100,
      price: Math.floor(Math.random() * 30) + 15 + Math.random()
    });
  }
  
  // 鎸夐攢鍞噺闄嶅簭鎺掑簭
  return topProducts.sort((a, b) => b.salesCount - a.salesCount);
}

// 杈呭姪鍑芥暟锛氱敓鎴愭渶杩戞祻瑙堢殑浜у搧
function generateLastBrowsedProducts(): Array<{ name: string; price: number }> {
  const products = [
    '鎷涚墝鐐掗キ', '榛勭剸楦＄背楗?, '楹昏荆棣欓攨', '瀹繚楦′竵', '灏忕倰鑲?, '姘寸叜鑲夌墖',
    '楸奸鑲変笣', '鍥為攨鑲?, '閰歌彍楸?, '楹诲﹩璞嗚厫', '杈ｅ瓙楦?, '骞查攨鐗涜倝',
    '钂滆嫈鐐掕倝', '钂滆搲瑗垮叞鑺?, '绯栭唻鎺掗', '绾㈢儳鐙瓙澶?, '涓滃潯鑲樺瓙', '绾㈢儳楸?,
    '钁辩垎缇婅倝', '閿呭寘鑲?, '姊呰彍鎵ｈ倝', '钂搁矆楸?, '閾佹澘鐗涙煶', '楹昏荆鐑?
  ];
  
  const lastBrowsedProducts = [];
  const usedProducts = new Set();
  
  // 鐢熸垚3-7涓渶杩戞祻瑙堢殑浜у搧
  const count = Math.floor(Math.random() * 5) + 3;
  
  for (let i = 0; i < count; i++) {
    let productName;
    
    // 纭繚浜у搧涓嶉噸澶?
    do {
      productName = products[Math.floor(Math.random() * products.length)];
    } while (usedProducts.has(productName));
    
    usedProducts.add(productName);
    
    lastBrowsedProducts.push({
      name: productName,
      price: Math.floor(Math.random() * 30) + 15 + Math.random()
    });
  }
  
  return lastBrowsedProducts;
}

// 杈呭姪鍑芥暟锛氱敓鎴愰殢鏈哄垎绫?
function getRandomCategories(): string[] {
  const categories = [
    '涓紡蹇', '瑗垮紡蹇', '鐏攨', '鐑х儰', '绮夐潰', '灏忓悆',
    '楗搧', '绯曠偣', '瀹跺父鑿?, '宸濊彍', '婀樿彍', '绮よ彍',
    '涓滃寳鑿?, '姹熸禉鑿?, '瑗垮寳鑿?, '绱犻', '娴烽矞', '鍐滃鑿?
  ];
  
  const selectedCategories = [];
  const categoryCount = Math.floor(Math.random() * 4) + 2; // 閫夋嫨2-5涓垎绫?
  
  const shuffled = [...categories].sort(() => 0.5 - Math.random());
  
  for (let i = 0; i < categoryCount; i++) {
    if (i < shuffled.length) {
      selectedCategories.push(shuffled[i]);
    }
  }
  
  return selectedCategories;
}

// 杈呭姪鍑芥暟锛氱敓鎴愰殢鏈哄湴鍖?
function getRandomRegions(): string[] {
  const regions = [
    '鍗庝笢鍦板尯', '鍗庡崡鍦板尯', '鍗庝腑鍦板尯', '鍗庡寳鍦板尯', '瑗垮崡鍦板尯', '瑗垮寳鍦板尯', '涓滃寳鍦板尯',
    '鍖椾含', '涓婃捣', '骞垮窞', '娣卞湷', '鏉窞', '鎴愰兘', '閲嶅簡', '姝︽眽', '鍗椾含', '鑻忓窞', 
    '澶╂触', '瑗垮畨', '閮戝窞', '闀挎矙', '闈掑矝', '瀹佹尝', '鍘﹂棬', '绂忓窞', '娴庡崡', '鍚堣偉'
  ];
  
  const selectedRegions = [];
  const regionCount = Math.floor(Math.random() * 5) + 2; // 閫夋嫨2-6涓湴鍖?
  
  const shuffled = [...regions].sort(() => 0.5 - Math.random());
  
  for (let i = 0; i < regionCount; i++) {
    if (i < shuffled.length) {
      selectedRegions.push(shuffled[i]);
    }
  }
  
  return selectedRegions;
}

// 杈呭姪鍑芥暟锛氱敓鎴愰《绾у垎閿€鍟?
function generateTopDistributors(): Array<{
  name: string;
  joinDate: string;
  activeReferrals: number;
  sales: number;
}> {
  const surnames = ['鏉?, '鐜?, '寮?, '鍒?, '闄?, '鏉?, '璧?, '榛?, '鍛?, '鍚?, '寰?, '瀛?, '鏈?, '椹?, '鑳?, '閮?, '鏋?, '浣?];
  const givenNames = ['鏄?, '鑺?, '鍐?, '鍗?, '寮?, '浼?, '鏉?, '濞?, '鑹?, '鏁?, '闈?, '涓?, '娑?, '瓒?, '鍕?, '娲?, '鐕?, '鏅?, '纾?, '鍋?, '楣?, '椋?];
  
  const topDistributors = [];
  
  // 鐢熸垚3-5涓《绾у垎閿€鍟?
  const count = Math.floor(Math.random() * 3) + 3;
  
  for (let i = 0; i < count; i++) {
    const surname = surnames[Math.floor(Math.random() * surnames.length)];
    const givenName = givenNames[Math.floor(Math.random() * givenNames.length)];
    
    topDistributors.push({
      name: surname + givenName,
      joinDate: getRandomPastDate(30, 365),
      activeReferrals: Math.floor(Math.random() * 15) + 1,
      sales: Math.floor(Math.random() * 50000) + 10000
    });
  }
  
  // 鎸夐攢鍞闄嶅簭鎺掑簭
  return topDistributors.sort((a, b) => b.sales - a.sales);
}

// 辅助函数（使用带参数版本内部实现）
function generateTopDistributors(): any[] {
  // 随机生成3-5个顶级分销商
  const count = randomInteger(3, 5);
  return generateTopDistributors(count);
}
